package DBLayer;

import ModelLayer.PartialAssignment;

import java.util.ArrayList;

import static org.junit.Assert.fail;

public class DBPartialAssignmentTest {


    @org.junit.Test()
    public void testGetAllPartialAssignments() throws Exception {
        ArrayList<PartialAssignment> partialAssignmentArrayList;
        DBPartialAssignment dbPartialAssignmentObj = new DBPartialAssignment();
        partialAssignmentArrayList = dbPartialAssignmentObj.getAllPartialAssignments();

        if (partialAssignmentArrayList != null){
            for (PartialAssignment part1 : partialAssignmentArrayList){
                System.out.println("idPartialAssignment : " + part1.getIdPartialAssignment() +
                        " HoursExpected : " +part1.getHourExpected() + " HoursSpent : " + part1.getHourSpent());
            }
        }
    }


    @org.junit.Test
    public void testFindPartialAssignmentId() throws Exception {
        DBPartialAssignment dbPart = new DBPartialAssignment();
        PartialAssignment part = dbPart.findPartialAssignmentId("151515");

        if (part != null){
           System.out.println("PartialAssignmentId has been found \n");
           System.out.println("idPartialAssignment :" + part.getIdPartialAssignment() + ", PartialAssignmentName :" + part.getNameAssignment());
        }
        else fail();
    }

    @org.junit.Test
    public void testFindPartialAssignmentName() throws Exception {
        DBPartialAssignment dbPart = new DBPartialAssignment();
        PartialAssignment part = dbPart.findPartialAssignmentName("Something something");

        if (part != null){
           System.out.println("PartialAssignmentName has been found \n");
           System.out.println("idPartialAssignment : " + part.getIdPartialAssignment() + ", PartialAssignmentName : " + part.getNameAssignment());
        }
       else fail();
    }


    @org.junit.Test
    public void testInsertPartialAssignment() throws Exception {
        PartialAssignment part = new PartialAssignment();

        part.setIdPartialAssignment("nextIdPartialAssignment");
                //part.setMaterialList().get(1).setIdMaterial();
                //part.setEmployee().setIdEmployee();
        part.setNameAssignment("Something something");
        part.setArea(10);
        part.setHourExpected(5);
        part.setHourSpent(2);
        part.setNote("Blablahblah something darkside");
        part.setPriceAssignment(22);

        DBPartialAssignment dbPart = new DBPartialAssignment();
        int i = dbPart.insertPartialAssignment(part);

        if(i == 1){
            System.out.println("Added");
        }
        else fail();
    }


    @org.junit.Test
    public void testUpdatePartialAssignment() throws Exception {
        PartialAssignment part = new PartialAssignment();
        DBPartialAssignment dbPart = new DBPartialAssignment();
        part = dbPart.findPartialAssignmentId("171718");

        part.setNameAssignment("Something10");

        int i = dbPart.updatePartialAssignment(part);
    }

    @org.junit.Test
    public void testDelete() throws Exception {
        PartialAssignment part = new PartialAssignment();
        DBPartialAssignment dbPart = new DBPartialAssignment();
        part = dbPart.findPartialAssignmentId("171718");

        if (part != null){
        int i = dbPart.deletePartialAssignment("171718");
        System.out.println(part.getIdPartialAssignment() + " Deleted");

        }
        else fail();
    }
}